package com.shortlink.gateway.config;

import com.shortlink.common.ratelimiter.CounterRateLimiter;
import com.shortlink.common.ratelimiter.RateLimiter;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 限流配置类
 *
 * @author wp
 */
@Configuration
public class RateLimiterConfiguration {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Bean
    public RateLimiter userRateLimiter(RateLimiterProperties rateLimiterProperties) {
        return new CounterRateLimiter(stringRedisTemplate, rateLimiterProperties);
    }
}
